'use strict';
const moment = require('moment');

module.exports = app => {
    const { STRING, INTEGER, DATE } = app.Sequelize;

    const Message = app.model.define('message', {
        id: { type: INTEGER, primaryKey: true, autoIncrement: true },
        username: STRING(64),
        book_num: STRING(64),
        book_name: STRING(64),
        revert_time: {
            type: DATE,
            get() {
                return moment(this.getDataValue('revert_time')).format('YYYY-MM-DD');
            },
        },
        content: {
            type: INTEGER(11),
            defaultValue: () => '请尽快归还!',
        },
        created_at: {
            type: DATE,
            defaultValue: () => {
                return moment(Date.now()).format('YYYY-MM-DD HH:mm:ss');
            },
            get() {
                return moment(this.getDataValue('created_at')).format('YYYY-MM-DD HH:mm:ss');
            },
        },
        updated_at: {
            type: DATE,
            defaultValue: () => {
                return moment(Date.now()).format('YYYY-MM-DD HH:mm:ss');
            },
            get() {
                return moment(this.getDataValue('updated_at')).format('YYYY-MM-DD HH:mm:ss');
            },
        },
        upt_act: { type: STRING(2), defaultValue: () => 'I' },
    });

    return Message;
};